home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / games / larn12s.arc / LARN.ARC / GLOBAL.C < prev    next >
C/C++ Source or Header  |  1987-10-28  |  16KB  |  622 lines

  1. /*    global.c         Larn is copyrighted 1986 by Noah Morgan.
  2.  *
  3.  *    raiselevel()        subroutine to raise the player one level
  4.  *    loselevel()        subroutine to lower the player by one level
  5.  *    raiseexperience(x)    subroutine to increase experience points
  6.  *    loseexperience(x)    subroutine to lose experience points
  7.  *    losehp(x)            subroutine to remove hit points from the player
  8.  *    losemhp(x)            subroutine to remove max # hit points from the player
  9.  *    raisehp(x)            subroutine to gain hit points
  10.  *    raisemhp(x)            subroutine to gain maximum hit points
  11.  *    losespells(x)        subroutine to lose spells
  12.  *    losemspells(x)        subroutine to lose maximum spells
  13.  *    raisespells(x)        subroutine to gain spells
  14.  *    raisemspells(x)        subroutine to gain maximum spells
  15.  *    recalc()            function to recalculate the armor class of the player
  16.  *    makemonst(lev)        function to return monster number for a randomly selected monster
  17.  *    positionplayer()    function to be sure player is not in a wall
  18.  *    quit()                subroutine to ask if the player really wants to quit
  19.  */
  20.  
  21. #include "header.h"
  22. extern int score[],srcount,dropflag;
  23. extern int random;/*    the random number seed            */
  24. extern short playerx,playery,lastnum;
  25. extern char cheat,level,monstnamelist[];
  26. extern char lastmonst[],*what[],*who[]; 
  27. extern char winner[];
  28. extern char logname[],monstlevel[];
  29. extern char sciv[SCORESIZE+1][26][2],*potionname[],*scrollname[];
  30. /*
  31.     ***********
  32.     RAISE LEVEL
  33.     ***********
  34.     raiselevel()
  35.  
  36.     subroutine to raise the player one level
  37.     uses the skill[] array to find level boundarys
  38.     uses c[EXPERIENCE]  c[LEVEL]
  39.  */
  40. raiselevel()
  41.     {
  42.     if (c[LEVEL] < MAXPLEVEL) raiseexperience((long)(skill[c[LEVEL]]-c[EXPERIENCE]));
  43.     }
  44.  
  45. /*
  46.     ***********
  47.     LOOSE LEVEL
  48.     ***********
  49.     loselevel()
  50.  
  51.     subroutine to lower the players character level by one
  52.  */
  53. loselevel()
  54.     {
  55.     if (c[LEVEL] > 1) loseexperience((long)(c[EXPERIENCE] - skill[c[LEVEL]-1] + 1));
  56.     }
  57.  
  58. /*
  59.     ****************
  60.     RAISE EXPERIENCE
  61.     ****************
  62.     raiseexperience(x)
  63.  
  64.     subroutine to increase experience points
  65.  */
  66. raiseexperience(x)
  67.     register long x;
  68.     {
  69.     register int i,tmp;
  70.     i=c[LEVEL];    c[EXPERIENCE]+=x;
  71.     while (c[EXPERIENCE] >= skill[c[LEVEL]] && (c[LEVEL] < MAXPLEVEL))
  72.         {
  73.         tmp = (c[CONSTITUTION]-c[HARDGAME])>>1;
  74.         c[LEVEL]++;    raisemhp((int)(rnd(3)+rnd((tmp>0)?tmp:1)));
  75.         raisemspells((int)rund(3));
  76.         if (c[LEVEL] < 7-c[HARDGAME]) raisemhp((int)(c[CONSTITUTION]>>2));
  77.         }
  78.     if (c[LEVEL] != i)
  79.         {
  80.         cursors();
  81.         beep(); lprintf("\nWelcome to level %d",(long)c[LEVEL]);    /* if we changed levels    */
  82.         }
  83.     bottomline();
  84.     }
  85.  
  86. /*
  87.     ****************
  88.     LOOSE EXPERIENCE
  89.     ****************
  90.     loseexperience(x)
  91.  
  92.     subroutine to lose experience points
  93.  */
  94. loseexperience(x)
  95.     register long x;
  96.     {
  97.     register int i,tmp;
  98.     i=c[LEVEL];        c[EXPERIENCE]-=x;
  99.     if (c[EXPERIENCE] < 0) c[EXPERIENCE]=0;
  100.     while (c[EXPERIENCE] < skill[c[LEVEL]-1])
  101.         {
  102.         if (--c[LEVEL] <= 1) c[LEVEL]=1;    /*    down one level        */
  103.         tmp = (c[CONSTITUTION]-c[HARDGAME])>>1;    /* lose hpoints */
  104.         losemhp((int)rnd((tmp>0)?tmp:1));    /* lose hpoints */
  105.         if (c[LEVEL] < 7-c[HARDGAME]) losemhp((int)(c[CONSTITUTION]>>2));
  106.         losemspells((int)rund(3));                /*    lose spells        */
  107.         }
  108.     if (i!=c[LEVEL])
  109.         {
  110.         cursors();
  111.         beep(); lprintf("\nYou went down to level %d!",(long)c[LEVEL]);
  112.         }
  113.     bottomline();
  114.     }
  115.  
  116. /*
  117.     ********
  118.     LOOSE HP
  119.     ********
  120.     losehp(x)
  121.     losemhp(x)
  122.  
  123.     subroutine to remove hit points from the player
  124.     warning -- will kill player if hp goes to zero
  125.  */
  126. losehp(x)
  127.     register int x;
  128.     {
  129.     if ((c[HP] -= x) <= 0)
  130.         {
  131.         beep(); lprcat("\n");  nap(3000);  died(lastnum);
  132.         }
  133.     }
  134.  
  135. losemhp(x)
  136.     register int x;
  137.     {
  138.     c[HP] -= x;        if (c[HP] < 1)        c[HP]=1;
  139.     c[HPMAX] -= x;    if (c[HPMAX] < 1)    c[HPMAX]=1;
  140.     }
  141.  
  142. /*
  143.     ********
  144.     RAISE HP
  145.     ********
  146.     raisehp(x)
  147.     raisemhp(x)
  148.  
  149.     subroutine to gain maximum hit points
  150.  */
  151. raisehp(x)
  152.     register int x;
  153.     {
  154.     if ((c[HP] += x) > c[HPMAX]) c[HP] = c[HPMAX];
  155.     }
  156.  
  157. raisemhp(x)
  158.     register int x;
  159.     {
  160.     c[HPMAX] += x;    c[HP] += x;
  161.     }
  162.  
  163. /*
  164.     ************
  165.     RAISE SPELLS
  166.     ************
  167.     raisespells(x)
  168.     raisemspells(x)
  169.  
  170.     subroutine to gain maximum spells
  171.  */
  172. raisespells(x)
  173.     register int x;
  174.     {
  175.     if ((c[SPELLS] += x) > c[SPELLMAX])    c[SPELLS] = c[SPELLMAX];
  176.     }
  177.  
  178. raisemspells(x)
  179.     register int x;
  180.     {
  181.     c[SPELLMAX]+=x; c[SPELLS]+=x;
  182.     }
  183.  
  184. /*
  185.     ************
  186.     LOOSE SPELLS
  187.     ************
  188.     losespells(x)
  189.     losemspells(x)
  190.  
  191.     subroutine to lose maximum spells
  192.  */
  193. losespells(x)
  194.     register int x;
  195.     {
  196.     if ((c[SPELLS] -= x) < 0) c[SPELLS]=0;
  197.     }
  198.  
  199. losemspells(x)
  200.     register int x;
  201.     {
  202.     if ((c[SPELLMAX] -= x) < 0) c[SPELLMAX]=0;
  203.     if ((c[SPELLS] -= x) < 0) c[SPELLS]=0;
  204.     }
  205.  
  206. /*
  207.     makemonst(lev)
  208.         int lev;
  209.  
  210.     function to return monster number for a randomly selected monster
  211.         for the given cave level    
  212.  */
  213. makemonst(lev)
  214.     register int lev;
  215.     {
  216.     register int tmp,x;
  217.     if (lev < 1)    lev = 1;            if (lev > 12)    lev = 12;
  218.     tmp=WATERLORD;
  219.     if (lev < 5)
  220.         while (tmp==WATERLORD) tmp=rnd((x=monstlevel[lev-1])?x:1);
  221.     else while (tmp==WATERLORD)
  222.         tmp=rnd((x=monstlevel[lev-1]-monstlevel[lev-4])?x:1)+monstlevel[lev-4];
  223.  
  224.     while (monster[tmp].genocided && tmp<MAXMONST) tmp++; /* genocided? */
  225.     return(tmp);
  226.     }
  227.  
  228. /*
  229.     positionplayer()
  230.  
  231.     function to be sure player is not in a wall
  232.  */
  233. positionplayer()
  234.     {
  235.     int try;
  236.     try = 2;
  237.     while ((item[playerx][playery] || mitem[playerx][playery]) && (try))
  238.         if (++playerx >= MAXX-1)
  239.             {
  240.             playerx = 1;
  241.             if (++playery >= MAXY-1)
  242.                 {    playery = 1;    --try;    }
  243.             }
  244.     if (try==0)     lprcat("Failure in positionplayer\n");
  245.     }
  246.  
  247. /*
  248.     recalc()    function to recalculate the armor class of the player
  249.  */
  250. recalc()
  251.     {
  252.     register int i,j,k;
  253.     c[AC] = c[MOREDEFENSES];
  254.     if (c[WEAR] >= 0)  
  255.         switch(iven[c[WEAR]])
  256.             {
  257.             case OSHIELD:        c[AC] += 2 + ivenarg[c[WEAR]]; break;
  258.             case OLEATHER:        c[AC] += 2 + ivenarg[c[WEAR]]; break;
  259.             case OSTUDLEATHER:    c[AC] += 3 + ivenarg[c[WEAR]]; break;
  260.             case ORING:            c[AC] += 5 + ivenarg[c[WEAR]]; break;
  261.             case OCHAIN:        c[AC] += 6 + ivenarg[c[WEAR]]; break;
  262.             case OSPLINT:        c[AC] += 7 + ivenarg[c[WEAR]]; break;
  263.             case OPLATE:        c[AC] += 9 + ivenarg[c[WEAR]]; break;
  264.             case OPLATEARMOR:    c[AC] += 10 + ivenarg[c[WEAR]]; break;
  265.             case OSSPLATE:        c[AC] += 12 + ivenarg[c[WEAR]]; break;
  266.             }
  267.  
  268.     if (c[SHIELD] >= 0) if (iven[c[SHIELD]] == OSHIELD) c[AC] += 2 + ivenarg[c[SHIELD]];
  269.     if (c[WIELD] < 0)  c[WCLASS] = 0;  else
  270.         {
  271.         i = ivenarg[c[WIELD]];
  272.         switch(iven[c[WIELD]])
  273.             {
  274.             case ODAGGER:    c[WCLASS] =  3 + i;  break;
  275.             case OBELT:         c[WCLASS] =  7 + i;  break;
  276.             case OSHIELD:     c[WCLASS] =  8 + i;  break;
  277.             case OSPEAR:     c[WCLASS] = 10 + i;  break;
  278.             case OFLAIL:     c[WCLASS] = 14 + i;  break;
  279.             case OBATTLEAXE: c[WCLASS] = 17 + i;  break;
  280.             case OLANCE:     c[WCLASS] = 19 + i;  break;
  281.             case OLONGSWORD: c[WCLASS] = 22 + i;  break;
  282.             case O2SWORD:    c[WCLASS] = 26 + i;  break;
  283.             case OSWORD:     c[WCLASS] = 32 + i;  break;
  284.             case OSWORDofSLASHING: c[WCLASS] = 30 + i; break;
  285.             case OHAMMER:    c[WCLASS] = 35 + i;  break;
  286.             default:         c[WCLASS] = 0;
  287.             }
  288.         }
  289.     c[WCLASS] += c[MOREDAM];
  290.  
  291. /*    now for regeneration abilities based on rings    */
  292.     c[REGEN]=1;        c[ENERGY]=0;
  293.     j=0;  for (k=25; k>0; k--)  if (iven[k]) {j=k; k=0; }
  294.     for (i=0; i<=j; i++)
  295.         {
  296.         switch(iven[i])
  297.             {
  298.             case OPROTRING: c[AC]     += ivenarg[i] + 1;    break;
  299.             case ODAMRING:  c[WCLASS] += ivenarg[i] + 1;    break;
  300.             case OBELT:     c[WCLASS] += ((ivenarg[i]<<1)) + 2;    break;
  301.  
  302.             case OREGENRING:    c[REGEN]  += ivenarg[i] + 1;    break;
  303.             case ORINGOFEXTRA:    c[REGEN]  += 5 * (ivenarg[i]+1); break;
  304.             case OENERGYRING:    c[ENERGY] += ivenarg[i] + 1;    break;
  305.             }
  306.         }
  307.     }
  308.  
  309.  
  310. /*
  311.     quit()
  312.  
  313.     subroutine to ask if the player really wants to quit
  314.  */
  315. quit()
  316.     {
  317.     register int i;
  318.     cursors();    strcpy(lastmonst,"");
  319.     lprcat("\n\nDo you really want to quit?");
  320.     while (1)
  321.         {
  322.         i=getchar();
  323.         if (i == 'y')    { died(300); return; }
  324.         if ((i == 'n') || (i == '\33'))    { lprcat(" no"); lflush(); return; }
  325.         lprcat("\n");  setbold();  lprcat("Yes");  resetbold();  lprcat(" or ");
  326.         setbold();  lprcat("No");  resetbold();  lprcat(" please